﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace MementoLibrary.DTOs
{
    public class WorkLogDTO : INotifyPropertyChanged
    {
        public WorkLogDTO()
        {
            CategoryIDs = new List<int>();
        }

        private int _workLogId;
        public int WorkLogId
        {
            get { return _workLogId; }
            set
            {
                _workLogId = value;
                PropertyChange("WorkLogId");
            }
        }

        private decimal _minutes;
        public decimal Minutes
        {
            get { return _minutes; }
            set
            {
                _minutes = value;
                PropertyChange("Minutes");
                PropertyChange("DisplayString");
            }
        }

        private DateTime _workdate;
        public DateTime Workdate
        {
            get { return _workdate; }
            set
            {
                _workdate = value;
                PropertyChange("Workdate");
                PropertyChange("DisplayString");
            }
        }

        private TaskDTO _task;
        public TaskDTO Task
        {
            get { return _task; }
            set
            {
                _task = value;
                PropertyChange("Task");
            }
        }

        public override string ToString()
        {
            return DisplayString;
        }

        public string DisplayString
        {
            get { return string.Format("{0} minutes on {1}", Minutes, Workdate.ToShortDateString()); }
        }

        public IEnumerable<int> CategoryIDs { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        public void PropertyChange(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
